/**
 * jims
 */
package com.jims.master.modules.drug.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.drug.entity.DrugNameDict;
import com.jims.master.modules.drug.service.DrugClassDictService;
import com.jims.master.modules.drug.service.DrugDictService;
import com.jims.master.modules.drug.service.DrugNameDictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 药品名称字典Controller
 * @author 朱齐
 * @version 2017-03-01
 */
@Controller
@RequestMapping(value = "${adminPath}/drug/drugNameDict")
public class DrugNameDictController extends BaseController {

	@Autowired
	private DrugNameDictService drugNameDictService;
    @Autowired
    private DrugDictService drugDictService;
    @Autowired
    private DrugClassDictService drugClassDictService;
	
	@ModelAttribute
	public DrugNameDict get(@RequestParam(required=false) String id) {
		DrugNameDict entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = drugNameDictService.get(id);
		}
		if (entity == null){
			entity = new DrugNameDict();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(DrugNameDict drugNameDict, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DrugNameDict> page = drugNameDictService.findPage(new Page<DrugNameDict>(request, response), drugNameDict); 
		model.addAttribute("page", page);
		return "modules/drug/drugNameDictIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = {"info", ""})
	public String info(DrugNameDict drugNameDict, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DrugNameDict> page = drugNameDictService.findPageByDict(new Page<DrugNameDict>(request, response), drugNameDict);
		model.addAttribute("page", page);
		return "modules/drug/drugInfo";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = {"query", ""})
	public String querylist(DrugNameDict drugNameDict, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DrugNameDict> page = drugNameDictService.findPage(new Page<DrugNameDict>(request, response), drugNameDict);
		model.addAttribute("page", page);
		return "modules/drug/drugInfoQueryIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(DrugNameDict drugNameDict, Model model) {
		model.addAttribute("drugNameDict", drugNameDict);
		return "modules/drug/drugNameDictForm";
	}

    /*
    * @zhuq
    * 保存drug_name_dict
    * */
	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(DrugNameDict drugNameDict, Model model) {
	    StringData data=new StringData();

		int i=drugNameDictService.saveDrugName(drugNameDict);
        if(i>0){
            data.setCode("success");
            data.setData("保存药品名称字典成功");
        }else{
            data.setCode("error");
            data.setData("保存药品名称字典失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(DrugNameDict drugNameDict) {
	    StringData data=new StringData();
		int i=drugNameDictService.delete(drugNameDict);
        if(i>0){
            data.setCode("success");
            data.setData("删除药品名称字典成功");
        }else{
            data.setCode("error");
            data.setData("删除药品名称字典失败");
        }
		return data;
	}


//    //==============================================
//    @RequiresPermissions("user")
//    @RequestMapping(value = "saveDrugNameDictExcel")
//    public String saveDrugNameDictExcel(Model model) {
//        drugNameDictService.saveDrugNameDictExcel();
//        return "";
//    }
//
//    //==============================================
//    @RequiresPermissions("user")
//    @RequestMapping(value = "saveDrugDictExcel")
//    public String saveDrugDictExcel(Model model) {
//        drugDictService.saveDrugDictExcel();
//        return "";
//    }
//
//    //==============================================
//    @RequiresPermissions("user")
//    @RequestMapping(value = "saveInfoPriceExcel")
//    public String saveInfoPriceExcel(Model model) {
//        drugNameDictService.saveInfoPriceExcel();
//        return "";
//    }

}